<template>
  <div>
    <el-breadcrumb separator="/" style="height:30px">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>分类管理</el-breadcrumb-item>
      <el-breadcrumb-item>分类列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card" style="width:600px">
      <el-table ref="multipleTable" :data="categoryList" tooltip-effect="dark" style="width: 100%">
        <el-table-column prop="name" label="类别名称" width="150"></el-table-column>
        <el-table-column prop="count" label="新闻数量" width="200"></el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              type="danger"
              icon="el-icon-delete"
              circle
              size="mini"
              @click="deleteCategoryByCidFu(scope.row.c_id)"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { selectCategoryList,deleteCategoryByCid } from "../../api";
export default {
  data() {
    return {
      categoryList: []
    };
  },
  created() {
    this.selectCategoryListFu();
  },
  methods: {
    /**查询分类 */
    async selectCategoryListFu() {
      let { data } = await selectCategoryList();
      this.categoryList = data.data;
    },
    // 删除分类
    deleteCategoryByCidFu(Id) {
      this.$confirm("此操作将永久删除分类及分类下新闻, 是否继续?", "提示", {
        type: "warning"
      })
        .then(async () => {
           let { data } = await deleteCategoryByCid(Id);
          if (data.code == 1) {
            this.$message.success(data.msg);
            this.selectCategoryListFu();
          } else {
            this.$message.error(data.msg);
          }
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    }
  }
};
</script>

<style scoped>
</style>